public class texttwo {//求出乱序数组按数组循序的第k个元素值

    public static int tsort(int[] arr, int a, int b, int k) {//a为开始，b为终止，k为查找值
        int q = seachersort(arr, a, b);
        if (q == k - 1) return arr[q];
        else if (q > k - 1) return tsort(arr, a, q - 1, k);
        else return tsort(arr, q + 1, b, k);
    }


    public static int seachersort(int[] arr, int a, int b) {
        int piovt = arr[a];//主元值
        int begin = a + 1;//扫描指针
        int end = b;//终止指针
        while (begin <= end) {
            if (piovt >= arr[begin]) {
                begin++;
            } else {
                int t = arr[begin];
                arr[begin] = arr[end];
                arr[end] = t;
                end--;
            }
        }
        int t1 = arr[end];
        arr[end] = piovt;
        arr[a] = t1;
        return end;
    }

    public static void main(String args[]) {
        int[] arr = {1, 3, 2, 7, 5, 4, 9, 11};
        System.out.println(tsort(arr, 0, arr.length - 1, 8));

    }

}
//  if(q<k-1){
//        tsort(arr,q+1,b,k);
//    }
//               if(q>k-1){
//        tsort(arr,a,q-1,k);
//    }
//               if(q==k-1)
//            System.out.println(arr[q]);
//}
//           if(a>=b){
//                   System.out.println(arr[k-1]);
//                   }